package com.tangding.hprose.api.server.command.impl.watch;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.tangding.cache.UserWatchingCache;
import com.tangding.common.exception.GException;
import com.tangding.hprose.api.server.command.Command;
import com.tangding.hprose.api.server.command.Response;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年12月18日_下午4:11:30
 *
 */
@Component
public class CancelWatchingUsers implements Command {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Response exe(Object... params) throws GException {
		Map<String, Object> user = (Map<String, Object>) params[params.length - 1];
		String uid = (String) user.get("uid");
		Set<Object> watchingUids = UserWatchingCache.getSet(uid);
		
		if (watchingUids != null) {
			Map<String, Object> map = (Map) params[0];
			List<Object> list = (List<Object>) map.get("uids");
			if (list != null) {
				for (Object id : list) {
					watchingUids.remove(id);
				}
			}
		}
		return doResponseSucc(true);
	}

}
